require('page/common/header/index.js')

var _order_service = require('service/order-service.js');
var _totalPrice
var confirmOrder = {
    init: function () {
        this.bindEvents();
        this.loadOrder();
        return this;
    },


    bindEvents: function () {
        var that = this
        $('#confirmed').on('click', function () {
            that.submit()
        });
        
    },
    loadOrder: function () {

        _order_service.getChangeOrder(
            function (resp) {
                console.log(resp);
                $("#creditCard").text(resp.creditCard);
                $("#expiryDate").text(resp.expiryDate);
                $("#billToFirstName").text(resp.billToFirstName);
                $("#billToLastName").text(resp.billToLastName);
                $("#billAddress1").text(resp.billAddress1);
                $("#billAddress2").text(resp.billAddress2);
                $("#billCity").text(resp.billCity);
                $("#billState").text(resp.billState);
                $("#billZip").text(resp.billZip);
                $("#billCountry").text(resp.billCountry);
                $("#shipToFirstName").text(resp.shipToFirstName);
                $("#shipToLastName").text(resp.shipToLastName);
                $("#shipAddress1").text(resp.shipAddress1);
                $("#shipAddress2").text(resp.shipAddress2);
                $("#shipCity").text(resp.shipCity);
                $("#shipState").text(resp.shipState);
                $("#shipZip").text(resp.shipZip);
                $("#shipCountry").text(resp.shipCountry);
                _totalPrice = resp.totalPrice
            }
            ,
            function (erroMsg) {
                console.log(erroMsg);
            }
        )
    },

    
    submit: function () {
        _order_service.getPay(
            _totalPrice,
            function (resp){
                console.log(resp)
                document.write(resp)
                
            }
            ,
            function (errMsg){
                console.log(errMsg)
            }
        )
    }
}

module.exports = confirmOrder.init();